home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 2000 November: Tool Chest / Dev.CD Nov 00 TC Disk 1.toast / Sample Code / Archive / Graphics / QuickDraw GX / GX->PostScript Sample / GXToPostScript / Imaging Engine / InkDrone.c < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-28  |  5.3 KB  |  212 lines  |  [TEXT/MPS ]

  1. /*
  2.      File:        InkDrone.c
  3.  
  4.      Contains:    QuickDraw GX to PostScript conversion code.
  5.                          File contains the ink drone.  This used to be in ShapeParts
  6.                         but was extracted for the purpose of segmentation
  7.  
  8.      Version:    Technology:    Quickdraw GX 1.1.x
  9.       
  10.      Copyright:    © 1992-1997 by Apple Computer, Inc., all rights reserved.
  11. */
  12.  
  13. #include "GXToPSBuildConfig.h"
  14. #include <GXGraphics.h>
  15. #include "GXGraphicsPriv.h"
  16. #include <GXEnvironment.h>
  17. #include "GXToPostScript.h"
  18. #include "IOUtilities.h"
  19. #include "RDUtil.h"
  20. #include "FontHandler.h"
  21. #include "PublicPostScriptIE.h"
  22. #include "private.h"
  23. #include "PSIEResources.h"
  24. #include "GXErrors.h"
  25. #include "ShapeUtilities.h"
  26.  
  27. #ifdef resumeLabel
  28.     #undef resumeLabel
  29. #endif
  30. #define resumeLabel(exception)
  31.  
  32. //<FF>
  33. /************************************
  34.     InkDrone:
  35.     
  36.     Convert the gx graphics Ink into PostScript or
  37.     use the PostScript synonym on the Ink.
  38.     
  39.     Routine converts the color into the specified
  40.     shape color space and then dispatches to the
  41.     appropriate color primitive.
  42.     
  43.     It is assumed that transfer modes (other than or-mode)
  44.     are pre-resolved so They are ignored by the Ink drone.
  45.     (That is until there is a version of PostScript that
  46.     supports Transfer Modes)
  47.     
  48.     The Ink drone will also check for the Ink synonym and
  49.     use it if it exists.
  50.     
  51.     hIEGlobals:            the Imaging Engine globals
  52.     theInk:                    The ink to translate.
  53.     theShape:                The shape it came from.
  54.     
  55. *************************************/
  56. OSErr _InkDrone(TIEGlobalsHdl hIEGlobals, gxInk theInk)
  57.     {
  58.         OSErr                        status = noErr;
  59.         TIEGlobalsPtr        pGlobals;
  60.         TRDParams                *pRDParams;
  61.         gxColor                    theColor;
  62.         gxColorSpace        theSpace;
  63.         short                        orMode;
  64.         gxColorProfile    theProfile;
  65.         long                        nSyn, i;
  66.         gxTag                        psSynonym;
  67.         gxTag                        halftoneTag;
  68.         TGstate                    *pGstate;
  69.  
  70.  
  71.         pGlobals = *hIEGlobals;
  72.         pRDParams = pGlobals->pRDParams;
  73.         
  74.         nSyn = GXGetInkTags(theInk, gxPostScriptTag, 1, gxSelectToEnd, nil);
  75.         
  76.         if (nSyn > 0) {
  77.  
  78.             nrequire(status = EndProcSetDict(pRDParams), failed_Ink);
  79.             nrequire(status = RDFlushBuffer(pRDParams->rdMap), failed_Ink);        /* OutputTag calls buffer data message dirctly*/
  80.  
  81.             for (i = 1; i <= nSyn; ++i) {
  82.             
  83.                 GXGetInkTags(theInk, gxPostScriptTag, i, 1, &psSynonym);
  84.                 nrequire(status = OutputTag(hIEGlobals, psSynonym), failed_Ink);
  85.                 
  86.             }//end for
  87.             
  88.             nrequire(status = BeginProcSetDict(pRDParams), failed_Ink);
  89.  
  90.             (*hIEGlobals)->ieStateFlags |= eInkOutOfDate;
  91.         
  92.         } else {
  93.         
  94.             /** First deal with any potential halftone tags. **/
  95.             
  96.             if (GXGetInkTags(theInk, gxFormatHalftoneTag, 1, gxSelectToEnd, nil))
  97.                 GXGetInkTags(theInk, gxFormatHalftoneTag, 1, 1, &halftoneTag);
  98.             else
  99.                 halftoneTag = nil;
  100.                 
  101.             pGlobals = *hIEGlobals;
  102.             pGstate = &(pGlobals->gStateNest[pGlobals->gStateDepth]);
  103.             
  104.             if ( (pGstate->halftoneTag != halftoneTag) ) {
  105.             
  106.                 if (halftoneTag != nil) {
  107.                 
  108.                     gxFormatHalftoneInfo            *halftoneInfo;
  109.                                                                 
  110.                     GXLockTag(halftoneTag);
  111.                     halftoneInfo = (gxFormatHalftoneInfo*)GXGetTagStructure(halftoneTag, nil);
  112.                     
  113.                     status = HalftonePrimitive(hIEGlobals, halftoneInfo);
  114.                     GXUnlockTag(halftoneTag);
  115.                     
  116.                     nrequire(status, failed_Halftone);
  117.                 
  118.                 } else {
  119.                 
  120.                     pRDParams->resIndex = kSetDefaultScreen;
  121.                     nrequire(status = RDResPrintf(pRDParams), failed_Halftone);
  122.                 
  123.                 }//end if
  124.                 
  125.                 /** Make sure graphics state owns the halftone **/
  126.                 pGstate = &((*hIEGlobals)->gStateNest[pGlobals->gStateDepth]);
  127.                 
  128.                 if (pGstate->halftoneTag != nil)
  129.                     GXDisposeTag(pGstate->halftoneTag);
  130.                     
  131.                 pGstate->halftoneTag = halftoneTag;
  132.                 if (halftoneTag != nil)
  133.                     GXCloneTag(halftoneTag);
  134.             
  135.             }//end if
  136.             
  137.             /** We'll need the color **/
  138.             
  139.             GXGetInkColor(theInk, &theColor);
  140.     
  141.             /** Output the orModeness of the ink for bitmap shapes and shapes with 1-bit bitmap patterns **/
  142.             
  143.             orMode = TestInkModeOr(theInk);
  144.     
  145.             pGlobals = *hIEGlobals;
  146.             if ( (orMode != pGlobals->orMode) || (pGlobals->ieStateFlags & eTmodeOutOfDate) ) {
  147.                             
  148.                 pGlobals->orMode = orMode;
  149.                                     
  150.                 pRDParams->resIndex = kSetOrMode;
  151.                 nrequire(status = RDResPrintf(pRDParams, orMode), failed_Mode);
  152.             
  153.             }//end if
  154.             
  155.             /** Now deal with the color **/
  156.                         
  157.             pGlobals = *hIEGlobals;
  158.             
  159.             if (pGlobals->params.renderOptions & gxUseLevel2ColorOption) {
  160.             
  161.                 status = Level2ColorPrimitive(hIEGlobals, &theColor);
  162.                 ncheck(status);
  163.             
  164.             } else { 
  165.             
  166.                 theSpace = pGlobals->params.devCSpace;
  167.                 theProfile = pGlobals->params.devCProfile;
  168.  
  169.                 GXConvertColor(&theColor, theSpace, nil, theProfile);
  170.                 nrequire(status = GXGetGraphicsError(nil), failed_ConvertColor);
  171.         
  172.                 switch (theSpace) {
  173.                 
  174.                     case gxRGBSpace:
  175.                         status = RGBColorPrimitive(hIEGlobals, &(theColor.element.rgb));
  176.                         ncheck(status);
  177.                         break;
  178.                         
  179.                     case gxGraySpace:
  180.                         status = GrayColorPrimitive(hIEGlobals, theColor.element.gray);
  181.                         ncheck(status);
  182.                         break;
  183.                         
  184.                     case gxCMYKSpace:
  185.                         status = CMYKColorPrimitive(hIEGlobals, &(theColor.element.cmyk));
  186.                         ncheck(status);
  187.                         break;
  188.                     
  189.                     default:
  190.                         #if DEBUGLEVEL > 0
  191.                             dprintf(notrace, "Requested color space (%d) Invalid", theSpace);
  192.                         #endif
  193.                         status = colorSpace_out_of_range;
  194.                         break;
  195.                 
  196.                 }//end switch
  197.                 
  198.             }//end if
  199.             
  200.             (*hIEGlobals)->ieStateFlags &= ~eInkOutOfDate;
  201.  
  202.         }//end if
  203.         
  204. failed_Mode:
  205. failed_ConvertColor:
  206. failed_Halftone:
  207. failed_Ink:
  208.         return(status);
  209.         
  210.     }//InkDrone
  211.     
  212.